{ lib, scrubDerivation }:

let
  # List of packages that need to be scrubbed on Darwin
  # Packages are scrubbed on Linux and expected in test output
  packagesToScrub = [
    # keep-sorted start case=no numeric=yes
    "aerc"
    "aerospace"
    "aichat"
    "alacritty"
    "alot"
    "antidote"
    "anvil-editor"
    "aria2"
    "atuin"
    "autojump"
    "bacon"
    "bash"
    "bash-completion"
    "bash-preexec"
    "bashInteractive"
    "bat"
    "borgmatic"
    "bottom"
    "broot"
    "browserpass"
    "btop"
    "carapace"
    "cava"
    "claude-code"
    "clock-rs"
    "cmus"
    "codex"
    "comodoro"
    "cudatext"
    "darcs"
    "delta"
    "difftastic"
    "dircolors"
    "direnv"
    "discord"
    "discoss"
    "earthly"
    "element-desktop"
    "emacs"
    "espanso"
    "eza"
    "fastfetch"
    "feh"
    "fzf"
    "gallery-dl"
    "getconf"
    "gh"
    "gh-dash"
    "ghostty"
    "git"
    "git-cliff"
    "git-credential-oauth"
    "git-lfs"
    "git-worktree-switcher"
    "gitMinimal"
    "gnupg"
    "go"
    "gradle"
    "granted"
    "helix"
    "hello"
    "himalaya"
    "hjson-go"
    "htop"
    "hyfetch"
    "i3status"
    "inori"
    "irssi"
    "isync"
    "jankyborders"
    "joplin-desktop"
    "jqp"
    "jujutsu"
    "k9s"
    "kakoune"
    "khal"
    "khard"
    "kitty"
    "kubecolor"
    "kubeswitch"
    "lapce"
    "lazydocker"
    "lazygit"
    "lazysql"
    "ledger"
    "less"
    "lesspipe"
    "lf"
    "lieer"
    "lsd"
    "mbsync"
    "meli"
    "mergiraf"
    "micro"
    "mise"
    "mpv"
    "msmtp"
    "mu"
    "mujmap"
    "mullvad-vpn"
    "ncmpcpp"
    "ne"
    "neomutt"
    "neovide"
    "neovim"
    "newsboat"
    "nh"
    "nheko"
    "nix"
    "nix-direnv"
    "nix-index"
    "nix-init"
    "nix-your-shell"
    "notmuch"
    "npth"
    "nushell"
    "nyxt"
    "oh-my-posh"
    "ollama"
    "onlyoffice-desktopeditors"
    "opencode"
    "openssh"
    "openstackclient"
    "papis"
    "patdiff"
    "pay-respects"
    "pet"
    "pgcli"
    "pistol"
    "pls"
    "poetry"
    "powerline-go"
    "pubs"
    "pyenv"
    "qcal"
    "qutebrowser"
    "ranger"
    "retext"
    "rio"
    "ripgrep"
    "ruff"
    "sage"
    "sapling"
    "sbt"
    "scmpuff"
    "senpai"
    "sftpman"
    "sioyek"
    "skhd"
    "sm64ex"
    "smug"
    "spotify-player"
    "starship"
    "superfile"
    "taskwarrior2"
    "tealdeer"
    "texlive"
    "thefuck"
    "thunderbird"
    "tmate"
    "tmux"
    "topgrade"
    "translate-shell"
    "tray-tui"
    "vifm"
    "vim-vint"
    "vimPlugins"
    "visidata"
    "vscode"
    "wallust"
    "watson"
    "wezterm"
    "yazi"
    "yq-go"
    "yubikey-agent"
    "zed-editor"
    "zellij"
    "zk"
    "zoxide"
    "zplug"
    "zsh"
    "zsh-history-substring-search"
    # keep-sorted end
  ];

  # Create an overlay that scrubs packages in the scrublist
  packageScrubOverlay =
    self: super:
    lib.mapAttrs (
      name: value:
      if lib.elem name packagesToScrub then
        # Apply scrubbing to this specific package
        scrubDerivation name value
      else
        value
    ) super;

in
self: super:
packageScrubOverlay self super
// {
  buildPackages = super.buildPackages.extend packageScrubOverlay;
}
